#include "camprec.h"
#include "DrawArray.h"

//DWORD CDrawArray::m_ID = 0;

CDrawArray::CDrawArray(void)//:IDOGL(0)
{
	//m_ID++;
	//StrID (mystr::format(_T("DrawArray%d"),m_ID));

	m_VertexPointer_size = 3;
	m_VertexPointer_type = GL_DOUBLE; 
	m_VertexPointer_stride = 0;
	m_pVertexPointer = NULL; 
	m_VertexPointer_count = 0;

	m_NormalPointer_type = GL_DOUBLE; 
	m_NormalPointer_stride = 0;
	m_pNormalPointer = NULL;
	m_NormalPointer_count = 0;
	
	
	m_ColorPointer_size = 3;
	m_ColorPointer_type = GL_DOUBLE;
	m_ColorPointer_stride = 0;
	m_pColorPointer = NULL;
	m_ColorPointer_count = 0;

	m_DrawArray_mode = GL_POINTS;
	m_DrawArray_count = 0;
	m_DrawArray_first = 0;


}

CDrawArray::~CDrawArray(void)
{
	delete [] m_pVertexPointer;
	delete [] m_pNormalPointer;
	delete [] m_pColorPointer;
}



GLdouble* CDrawArray::InitVertexPointer (const GLint &VertexPointer_count, const GLint &VertexPointer_size, const GLsizei &VertexPointer_stride)
{
	m_VertexPointer_count = 0; 
	delete [] m_pVertexPointer;

	if (VertexPointer_count == 0)
		return NULL;
	m_pVertexPointer = new GLdouble [VertexPointer_size * VertexPointer_count];

	if (m_pVertexPointer)
	{
		m_VertexPointer_count = VertexPointer_count;
		m_VertexPointer_size = VertexPointer_size;
		m_VertexPointer_stride = VertexPointer_stride;
	}

	return m_pVertexPointer;
}

GLdouble *CDrawArray::InitNormalPointer (GLint NormalPointer_count, GLsizei NormalPointer_stride)
{
	m_NormalPointer_count = 0;
	delete [] m_pNormalPointer;

	if (NormalPointer_count == 0)
		return NULL;
	m_pNormalPointer = new GLdouble [3 * NormalPointer_count];
	if (m_pNormalPointer)
	{
		m_NormalPointer_count = NormalPointer_count;
		m_NormalPointer_stride = NormalPointer_stride;
	}
	return m_pNormalPointer;
}

GLdouble *CDrawArray::InitColorPointer (GLint ColorPointer_count, GLint ColorPointer_size_3or4, GLsizei ColorPointer_stride)
{
	m_ColorPointer_count = 0; 
	delete [] m_pColorPointer;
	m_pColorPointer = NULL;

	if (ColorPointer_count == 0)
		return NULL;

	if ((ColorPointer_size_3or4<3)||(ColorPointer_size_3or4>4))
		return NULL;

	m_pColorPointer = new GLdouble [ColorPointer_size_3or4 * ColorPointer_count];

	if (m_pColorPointer)
	{
		m_ColorPointer_count = ColorPointer_count;
		m_ColorPointer_size = ColorPointer_size_3or4;
		m_ColorPointer_stride = ColorPointer_stride;
	}

	return m_pColorPointer;
}
